<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('订单详细')" />
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeIn">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>订单基础信息</h5>
                </div>
                <div class="ibox-content">
                    <form class="form-horizontal m" id="form-user-edit">
                        <input type="hidden"  name="scmOrderId" id="scmOrderId" th:field="*{order.scmOrderId}"  />

                        <div class="form-group">
                            <label class="col-sm-3 control-label">SCM订单ID：</label>
                            <div class="col-sm-8">
                                <div class="form-control-static" th:text="${order.scmOrderId}"></div>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">OMS订单id：</label>
                            <div class="col-sm-8">
                                <div class="form-control-static" th:text="${order.orderid}"></div>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">订单来源：</label>
                            <div class="col-sm-8">
                                <div class="form-control-static" th:text="${order.orderSource}"></div>
                            </div>
                        </div>


                        <div class="form-group">
                            <label class="col-sm-3 control-label">项目名称：</label>
                            <div class="col-sm-8">
                                <div class="form-control-static" th:text="${order.projectName}"></div>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">单位名称：</label>
                            <div class="col-sm-8">
                                <div class="form-control-static" th:text="${order.companyName}"></div>
                            </div>
                        </div>


                        <div class="form-group">
                            <label class="col-sm-3 control-label">订单总额：</label>
                            <div class="col-sm-8">
                                <div class="form-control-static" th:text="${order.amountStr}"></div>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">订单状态：</label>
                            <div class="col-sm-8">
                                <div class="form-control-static" th:text="${order.orderStatusDesc}"></div>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">签收单：</label>
                            <div class="col-sm-8">
                                <div class="form-control-static" th:if="${#strings.isEmpty(order.receiptFile)}" >
                                    <p>签收人:<span th:text="${order.uploadWaitReceiptFileUser}"></span></p>
                                    <p>签收时间:<span th:text="${order.uploadWaitReceiptFileUser}"></span></p>
                                </div>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">发票：</label>
                            <div class="col-sm-8">
                                <a th:href="${order.invoicePath}" th:if="${order.invoiceStatus} eq '1' " target="_blank">下载发票</a>
                                <span  th:if="${order.invoiceStatus} ne '1'" target="_blank">未开发票</span>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-3 control-label">待签收单：</label>
                            <div class="col-sm-8">
                                <a th:href="${order.waitReceiptFile}" th:if=" (${order.receiptFielStatus} eq '1' or  ${order.receiptFielStatus} eq '2') and ${not #strings.isEmpty(order.waitReceiptFile)} " target="_blank">下载待签收单</a>
                                <span  th:if="(${order.receiptFielStatus} ne '1' and ${order.receiptFielStatus} ne '2' ) or ${#strings.isEmpty(order.waitReceiptFile)} " target="_blank">未上传</span>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-3 control-label">签收单：</label>
                            <div class="col-sm-8">
                                <a th:href="${order.receiptFile}" th:if="${order.receiptFielStatus} eq '2' " target="_blank">下载</a>
                                <span  th:if="${order.receiptFielStatus} ne '2'" target="_blank">未上传</span>
                            </div>
                        </div>

                    </form>

                </div>
            </div>
        </div>
    </div>
    <div class="row">
        <div >
            <div class="tabs-container">
                <ul class="nav nav-tabs">
                    <li class="active"><a data-toggle="tab" href="#tab-1" aria-expanded="true"> 商品明细信息</a>
                    </li>
                    <li class=""><a data-toggle="tab" href="#tab-2" aria-expanded="false">操作记录</a>
                    </li>
                </ul>


                <div class="tab-content">
                    <div id="tab-1" class="tab-pane active">
                        <div class="panel-body">
                            <div class="btn-group-sm" id="toolbar" role="group">

                                <a class="btn btn-primary single " onclick="caigou()" >
                                    <i class="fa fa-edit"></i> 转采购
                                </a>
                                <a class="btn btn-primary single " onclick="outInventory()" >
                                    <i class="fa fa-edit"></i> 转出库单
                                </a>

                            </div>

                            <div class="col-xs-12 select-table table-striped">
                                <table id="bootstrap-table1"></table>
                            </div>
                        </div>
                    </div>

                    <div id="tab-2" class="tab-pane">
                        <div class="panel-body">

                            <table id="bootstrap-table2"></table>

                        </div>
                    </div>
                </div>


            </div>
        </div>


    </div>

<th:block th:include="include :: footer" />
<script type="text/javascript">
    var prefix = ctx + "scm/order";

    $(function() {

        var options = {
            id: "bootstrap-table1",
            formId: "form1",
            toolbar: "toolbar1",
            url:  prefix+ "/product/list?orderId="+$("#scmOrderId").val(),
            modalName: "用户",
            showSearch: false,
            showRefresh: false,
            showToggle: false,
            showColumns: false,
            pagination: false,
            columns: [{
                checkbox: true
            },
                {
                    field : 'productCode',
                    title : '商品编码'
                },
                {
                    field : 'productName',
                    title : '商品名称'
                },
                {
                    field : 'productUnit',
                    title : '商品单位'
                },
                {
                    field : 'productPriceStr',
                    title : '商品价格'
                },
                {
                    field : 'productCount',
                    title : '订单数量'
                },
                {
                    field : 'sendCount',
                    title : '发货数量'
                },
                {
                    field : 'amountStr',
                    title : '小计金额'
                }
                ,
                {
                    field : 'statusDesc',
                    title : '商品状态'
                }   ,
                {
                    field : 'inventoryDesc',
                    title : '库存状态'
                }   ,
                {
                    field : 'productInventoryCount',
                    title : '库存数量'
                }

                ]
        };
        $.table.init(options);



        var options2 = {
            id: "bootstrap-table2",
            formId: "form1",
            toolbar: "toolbar1",
            url:  prefix+ "/log/list?orderId="+$("#scmOrderId").val(),
            modalName: "用户",
            showSearch: false,
            showRefresh: false,
            showToggle: false,
            showColumns: false,
            pagination: false,
            columns: [{
                checkbox: true
            },
                {
                    field : 'createTimeStr',
                    title : '时间'
                },
                {
                    field : 'operator',
                    title : '操作人'
                },
                {
                    field : 'operationTypeDesc',
                    title : '业务类型'
                },
                {
                    field : 'reamrk',
                    title : '描述'
                }

            ]
        };
        $.table.init(options2);

    });


    $("#form-user-add").validate({
        onkeyup: false,
        rules:{
            userPhone:{
                isPhone:true
            },
            userEmail:{
                email:true
            },
        },
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            $.operate.save(prefix + "/edit", $('#form-user-edit').serialize());
        }
    }

    function uploadCredentials(id){
        table.set();
        var currentId = 'uploadCredentialsimportTpl' ;
        var _width ="400" ;
        var _height = "230" ;
        debugger;

        top.layer.open({
            type: 1,
            area: [_width + 'px', _height + 'px'],
            fix: false,
            //不固定
            maxmin: true,
            shade: 0.3,
            title: '上传文件',
            content: $('#' + currentId).html(),
            btn: ['<i class="fa fa-check"></i> 上传文件', '<i class="fa fa-remove"></i> 取消'],
            // 弹层外区域关闭
            shadeClose: true,
            success:function (layero,index){
               // $("#uploadCredentialsimportTplId").val(id);
                layero.find('#uploadCredentialsimportTplId').val(id);
            },
            btn1: function(index, layero){
                var file = layero.find('#receipt_file').val();
                debugger;
                if (file == '' || (!$.common.endWith(file, 'pdf'))) {
                    $.modal.msgWarning("请选择后缀为 “pdf”的文件。");
                    return false;
                }
                var index = top.layer.load(2, {shade: false});
                $.modal.disable();
                var formData = new FormData(layero.find('form')[0]);
                $.ajax({
                    url: prefix+"/uploadCredentials",
                    data: formData,
                    cache: false,
                    contentType: false,
                    processData: false,
                    type: 'POST',
                    success: function (result) {
                        if (result.code == web_status.SUCCESS) {
                            log.info("return url：" + result.url)
                            log.info("reutrn fileName：" + result.fileName)
                            log.info("reutrn newFileName：" + result.newFileName)
                            log.info("return originalFilename：" + result.originalFilename)
                            $.modal.close(index);
                            $.modal.enable();
                            //$.modal.close();
                            //$.modal.closeAll();
                            $.modal.alertSuccess(result.msg);
                            //$.table.refresh();
                        } else if (result.code == web_status.WARNING) {
                            $.modal.close(index);
                            $.modal.enable();
                            $.modal.alertWarning(result.msg)
                        } else {
                            $.modal.close(index);
                            $.modal.enable();
                            $.modal.alertError(result.msg);
                        }
                    },
                    complete: function () {
                        layero.find('#receipt_file').val('');
                    }
                });
            }
        });
    }



    function caigou(){

        table.set();
        var rows = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
        if (rows.length == 0) {
            $.modal.alertWarning("请至少选择一条记录");
            return;
        }
        var ids = rows.join();
        console.log(ids);
        var data = { "ids": rows.join() };
        // $.modal.openTab("订单转出库单",ctx + "scm/inventory/out/orderToAdd/"+$("#scmOrderId").val());
        $.modal.openTab("订单转采购单",ctx + "system/purchase/orderToAdd?productIds="+ids);
    }


    function outInventory(){


        $.modal.openTab("订单转出库单",ctx + "scm/inventory/out/orderToAdd/"+$("#scmOrderId").val());


    }

</script>
<script id="uploadCredentialsimportTpl" type="text/template">
    <form enctype="multipart/form-data" class="mt20 mb10">
        <div class="col-xs-offset-1">
            订单属性:
            <select>
                <option value="zy">直营</option>
                <option value="dsf">第三方</option>
            </select>
            <input type="hidden"name="id" id="uploadCredentialsimportTplId" >
            <input type="file" id="receipt_file" name="receipt_file"/>
            <font color="red" class="pull-left mt10">
                提示：仅允许导入“pdf”格式文件！
            </font>
        </div>
    </form>
</script>

</body>
</html>
